cmake_minimum_required(VERSION 2.8.11)
project(PBACore)

# require Eigen
find_package( Eigen REQUIRED )
include_directories(${EIGEN_INCLUDE_DIR}) 

# add ceres
find_package(Ceres REQUIRED)
message("--Found Ceres library in ${CERES_INCLUDE_DIRS}")
include_directories(${CERES_INCLUDE_DIRS}/ceres
                    ${CERES_INCLUDE_DIRS})

include_directories(${PROJECT_SOURCE_DIR}/include)

# build the library
add_library(${PROJECT_NAME}
  src/DataManager.cpp
  src/Optimizer.cpp
  src/PBAFactors.cpp
  src/StateUpdateCallback.cpp)

# and link it
target_link_libraries(${PROJECT_NAME}
  PRIVATE ${CERES_LIBRARIES} 
)

# testing
if(BUILD_TESTS)
  enable_testing()
  set(PROJECT_TEST_NAME ${PROJECT_NAME}_test)
  add_executable(${PROJECT_TEST_NAME}
    #test/test_gradient.cpp
    test/test_jacobian3.cpp
    test/test_jacobian4.cpp
    test/test_main.cpp
  )
  target_link_libraries(${PROJECT_TEST_NAME} 
    ${PROJECT_NAME} 
    ${GTEST_LIBRARY}  
    pthread)
  add_test(test ${PROJECT_TEST_NAME})
endif()